package manager.customer.controller;
import common.ResponseEntity;
import io.swagger.annotations.Api;
import manager.customer.service.CustomerAuthService;
import manager.auth.utils.ResponseUtils;
import manager.auth.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = {"/customer/auth"})
@Api(value = "授权中心")
public class AuthCustomerController {
    @Autowired
    private CustomerAuthService customerAuthService;
    //登录
    @PostMapping("/login")
    public ResponseEntity<UserInfo> login(HttpServletResponse httpServletResponse, @RequestBody UserInfo userInfo) {
            String token = customerAuthService.authentication(userInfo.getUsername(), userInfo.getPassword());
            return ResponseUtils.getResponse(token,httpServletResponse,"shop_tick_tocken");
    }
    //校验token是否有效
    @GetMapping("verify")
    @RequestMapping(value = "verify", method = {RequestMethod.POST, RequestMethod.GET})
    public ResponseEntity<UserInfo> verify(HttpServletRequest request, HttpServletResponse response) {
           return ResponseUtils.virifyCookie(request,"shop_tick_tocken");
    }
}
